package com.ilop.sthome.ui.activity.main;

import android.content.Intent;
import androidx.databinding.ViewDataBinding;

import com.aliyun.alink.linksdk.tmp.api.DeviceManager;
import com.aliyun.iot.aep.sdk.login.ILogoutCallback;
import com.aliyun.iot.aep.sdk.login.LoginBusiness;
import com.aliyun.iot.push.PushManager;
import com.example.common.base.BasePresentActivity;
import com.example.common.mvp.IBasePresenter;
import com.example.common.utils.LiveDataBus;
import com.ilop.sthome.common.CommonId;

/**
 * @author skygge
 * @date 2020/7/30.
 * GitHub：javofxu@github.com
 * email：skygge@yeah.net
 * description：包含登出返回接口
 */
public class ContainLoginActivity<M extends IBasePresenter, A extends ViewDataBinding> extends BasePresentActivity<M, A> implements ILogoutCallback {

    @Override
    protected void initDataBus() {
        super.initDataBus();
        LiveDataBus.get().with(CommonId.LOGIN_OUT, Integer.class).observe(this, integer -> onLoginOut());
    }

    protected void onLoginOut(){
        PushManager.getInstance().unbindUser();
        DeviceManager.getInstance().clearAccessTokenCache();
        LoginBusiness.logout(this);
    }

    @Override
    public void onLogoutSuccess() {
        Intent intent = new Intent(mContext, StartActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
    }

    @Override
    public void onLogoutFailed(int i, String s) {

    }
}
